package com.atguigu.tingshu.listener;

import com.atguigu.tingshu.model.album.AlbumInfo;
import io.xzxj.canal.core.annotation.CanalListener;
import io.xzxj.canal.core.listener.EntryListener;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import java.util.Set;

/**
 * @author: jack
 * @date: 2025/10/10 15:25
 */
@Slf4j
@Component
@CanalListener(destination = "tingshuTopic", schemaName = "tingshu_album", tableName = "album_info")
public class AlbumInfoListener implements EntryListener<AlbumInfo> {


    @Autowired
    private RedisTemplate redisTemplate;

    @Override
    public void update(AlbumInfo before, AlbumInfo after, Set<String> fields) {
        log.info("更新专辑信息：{}", after);
        String key = "album:info: " + after.getId();
        redisTemplate.delete(key);
    }
}
